<html>
<head><meta charset="utf-8"><title>a question on unexported types · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/a.20question.20on.20unexported.20types.html">a question on unexported types</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="160775033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/a%20question%20on%20unexported%20types/near/160775033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pcpthm <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/a.20question.20on.20unexported.20types.html#160775033">(Mar 14 2019 at 12:32)</a>:</h4>
<p>Hello, while trying to use ra_hir, I found that many types returned from public methods are not exported publicly.<br>
For example, an enum <code>ra_hir::expr::Expr</code> which can be obtained from e.g. <code>function.body(db).exprs()</code> but can't be named from outside and thus can't be <code>match</code>ed. Is this restriction intended? I don't have an idea of the difference of what is exported vs what is not.</p>



<a name="160775198"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/a%20question%20on%20unexported%20types/near/160775198" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/a.20question.20on.20unexported.20types.html#160775198">(Mar 14 2019 at 12:35)</a>:</h4>
<p>It's just that we haven't thought about HIR API a lot.</p>



<a name="160775281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/a%20question%20on%20unexported%20types/near/160775281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/a.20question.20on.20unexported.20types.html#160775281">(Mar 14 2019 at 12:36)</a>:</h4>
<p>Currently, the only client of HIR is <code>ra_ide_api</code>, so hir <em>tries</em> to provide a nice API (see code_model_api), but this is done on best effort basis.</p>



<a name="160775406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/a%20question%20on%20unexported%20types/near/160775406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/a.20question.20on.20unexported.20types.html#160775406">(Mar 14 2019 at 12:38)</a>:</h4>
<p>I think, long term, hir will become the "systems boundary" between "compiler guts" and "tools", but that's not yet the case. Really, we should maybe try to split hir into separate crates soon...</p>



<a name="160775461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/a%20question%20on%20unexported%20types/near/160775461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/a.20question.20on.20unexported.20types.html#160775461">(Mar 14 2019 at 12:39)</a>:</h4>
<p>So, if something is missing, feel free to add it!</p>



<a name="160775591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/a%20question%20on%20unexported%20types/near/160775591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pcpthm <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/a.20question.20on.20unexported.20types.html#160775591">(Mar 14 2019 at 12:40)</a>:</h4>
<p>So only <code>code_model_api</code> module is what meant to be exposed?</p>



<a name="160775907"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/a%20question%20on%20unexported%20types/near/160775907" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/a.20question.20on.20unexported.20types.html#160775907">(Mar 14 2019 at 12:44)</a>:</h4>
<p>roughtly, yeah. Currently, code_model exports only top-level items, it doesn't export item bodies, but that's oversight. It would be cool to figure out the nice API for things like expressions. The current <code>hir::Expr</code> is a representation convenient for implementation, I am not sure it's a good API as well</p>



<a name="160775969"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/a%20question%20on%20unexported%20types/near/160775969" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/a.20question.20on.20unexported.20types.html#160775969">(Mar 14 2019 at 12:45)</a>:</h4>
<p>For example, I think for the public API we might want to bundle <code>hir::Expr</code> and the corresponding function together, so that you don't have to do deal with <code>Body</code> maps at all, and instead can just call methods on expr</p>



<a name="160776037"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/a%20question%20on%20unexported%20types/near/160776037" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/a.20question.20on.20unexported.20types.html#160776037">(Mar 14 2019 at 12:46)</a>:</h4>
<p>Or perhaps the body approach is good, but should be made more general</p>



<a name="160776078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/a%20question%20on%20unexported%20types/near/160776078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pcpthm <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/a.20question.20on.20unexported.20types.html#160776078">(Mar 14 2019 at 12:46)</a>:</h4>
<p>I understand. Thank you! I'm not sure about API either. Probably I can do some thinking.</p>



<a name="160776082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/a%20question%20on%20unexported%20types/near/160776082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/a.20question.20on.20unexported.20types.html#160776082">(Mar 14 2019 at 12:47)</a>:</h4>
<p>I mean, currently you need to ask resolver specifically for funciton bodies (or for generics). I think this can be abstracted away.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>